package com.woniu.service.impl;

import com.woniu.dao.InterviewDao;
import com.woniu.pojo.Interview;
import com.woniu.pojo.InterviewExample;
import com.woniu.pojo.PageBean;
import com.woniu.pojo.Student;
import com.woniu.service.InterviewService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class InterviewServiceImpl implements InterviewService {
    @Resource
    InterviewDao interviewDao;
    @Override
    public void addInterview(Interview interview) {
        interviewDao.insertSelective(interview);
    }
    @Override
    public List<Interview> InterviewListBySid(Integer sid, PageBean pageBean) {
        InterviewExample interviewExample=new InterviewExample();
        InterviewExample.Criteria criteria = interviewExample.createCriteria();
        criteria.andSidEqualTo(sid);
        interviewExample.setOrderByClause("itime desc");
        Long countRow= interviewDao.countByExample(interviewExample);
        pageBean.setCountRow(countRow.intValue());
        Integer countPage=pageBean.getCountRow()%pageBean.getPageSize()==0?pageBean.getCountRow()/pageBean.getPageSize():pageBean.getCountRow()/pageBean.getPageSize()+1;
        pageBean.setCountPage(countPage);
        //分页查询
        interviewExample.setOffset((long)((pageBean.getCurrentPage()-1)*pageBean.getPageSize()));
        interviewExample.setLimit(pageBean.getPageSize());

        List<Interview> interviewList=interviewDao.selectByExample(interviewExample);
       return interviewList;
    }

    @Override
    public void deleteinterviewByIno(Integer ino) {
        interviewDao.deleteByPrimaryKey(ino);
    }
}
